﻿using PickingGuide.Business;
using PickingGuide.Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PickingGuideForm
{
    public partial class FrmManualAdd : Form
    {
        public Action<List<ManualSetupModel>> RefreshUiEvent;
        //RackSetupBLL rackSetupBLL = new RackSetupBLL();
        ManualSetupBLL manualSetupBLL = new ManualSetupBLL();
        ManualSetupModel _manualPicking;
        //RackSetupModel _rack1;
        //RackSetupModel _rack2;
        List<ManualSetupModel> _queues;

        public FrmManualAdd(List<ManualSetupModel> list)
        {
            InitializeComponent();
            _queues = list;
            var list1 = manualSetupBLL.GetModelAll();

            cbManualPicking.DataSource = list1;
            cbManualPicking.DisplayMember = "Name";
            cbManualPicking.ValueMember = "ID";
            cbManualPicking.SelectedIndex = 0;

        }

        public FrmManualAdd(List<ManualSetupModel> list, ManualSetupModel manualPicking)
        {
            InitializeComponent();
            _manualPicking = manualPicking;

            _queues = list;
            var list1 = manualSetupBLL.GetModelAll();

            cbManualPicking.DataSource = list1;
            cbManualPicking.DisplayMember = "Name";
            cbManualPicking.ValueMember = "ID";
            cbManualPicking.SelectedValue = manualPicking.ID;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            var picking = cbManualPicking.SelectedItem as ManualSetupModel;

            if (_manualPicking != null)
            {
               var model =  _queues.Where(x => x.ID == _manualPicking.ID).FirstOrDefault();
                model = picking;
            }
            else
            {
                _manualPicking = picking;
                _queues.Add(_manualPicking);
            }
            RefreshUiEvent?.BeginInvoke(_queues,null, null);
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
